<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */
    include 'farmwork.php';
	header("content-type:text/html;charset=utf-8");
	login();
	include 'chushi.php';
	$sql = "SELECT * FROM `products` WHERE cp ='$ycp';";
	$result=mysqli_query($con,$sql);
	if($result&&mysqli_num_rows($result)){
	   while ($row=mysqli_fetch_assoc($result)) {
				$jg1 = $row['jg1'];
				$jg2 = $row['jg2'];
				$jg3 = $row['jg3'];
				$jg4 = $row['jg4'];
				$jg5 = $row['jg5'];
				$jg6 = $row['jg6'];
	   }
	}

	
	$uid = $_SESSION['user_uid'];
	$action = $_GET['action'];
	if($action=='do'){
		$time1 = $_POST['time'];
		if($time1=="+1day"){$xf=$jg1;}
		elseif($time1=="+7day"){$xf=$jg2;}
		elseif($time1=="+1month"){$xf=$jg3;}
		elseif($time1=="+3month"){$xf=$jg4;}
		elseif($time1=="+1year"){$xf=$jg5;}
		elseif($time1==""){$xf=$jg6;}

		$zhekouhou = $xf*$zhekou;
		if($rmb<$zhekouhou){
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">您的余额不足！<br>本次需要花费".$zhekouhou."元</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'authorize-add.php' });  }});</script>");
		}else{
		$rmb = $rmb - $zhekouhou;
		$logtime = $_POST['time'];

		$time = strtotime($logtime);
		$username = $_POST['username'];
		$domain = $_POST['domain'];
		$qq = $_POST['qq'];
		$syskey = $_POST['syskey'];
		$ycp = $_POST['ycp'];
		$pass = $_POST['pass'];
		$dl = '普通用户';
		$bz = $_POST['bz'];
		

	    $sql="select * from authorize where domain='$domain' and ycp='$ycp'";
        $query=mysqli_query($con,$sql);
        $rows = mysqli_num_rows($query);
		if($rows > 0){
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">授权已存在！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'authorize-add.php' });  }});</script>");
		}else{
		   $sql = "INSERT INTO `authorize` (`username`,`domain`,`pass`,`qq`,`time`,`version`,`syskey`,`yumi`,`ycp`,`rmb`,`dl`,`bz`,`up`) VALUES ('$username','$domain','$pass','$qq','$time','$version','$syskey','0','$ycp','0','$dl','$bz','$uid');";
		   mysqli_query($con,$sql);
		   $sql = "UPDATE `daili` SET `rmb` = '$rmb' where id='$uid'";
		   mysqli_query($con,$sql);
		    $ip = getip();
			$time1=time();
			$sql = "INSERT INTO `log_dl` (`uid`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$uid', '$time1', '$ycp', '-$zhekouhou', '$rmb', '添加授权*$logtime','$ip');";//添加流水日志
			mysqli_query($con,$sql);
		
		   mysqli_close();
		   echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">添加成功！</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'authorize.php' });  }});</script>");
		   die;
		}
	}}

$li1='class="active"';
$li11='class="active"';
?>
<?php include 'header.php';?>
    <title>添加授权-<?php echo $title?></title>
<?php include 'list.php';?>
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper">
<?php include 'overview.php';?>
            <div class="row">
                <div class="col-lg-12">
                    <!--work progress start-->
                    <section class="panel">
                        <div class="panel-body progress-panel">
                            <div class="task-progress">
                                <h1>添加新授权</h1>
                                <p>填写授权信息并保存.</p>
                            </div>
                        </div>
						<form action="authorize-add.php?action=do" method="post"  role="form">
                            <div class="form-group">
                                <label for="txtDomain">产品</label>
                                <select name="ycp" class="form-control" >
								
 									<?php 
											echo "<option value='".$ycp."'>".$ycp."</option>";											
									?>   
									</select>
                            </div>	
							<div class="form-group">
                                <label for="txtDomain">用户名</label>
                                <input type="text" name="username" class="form-control" placeholder="用户名" required/>
                            </div>					
                            						
                            <div class="form-group">
                                <label for="txtDomain">账号</label>
                                <input type="text" name="domain" class="form-control" placeholder="登录账号" autocomplete="off" required/>
                            </div>
                           <div class="form-group">
                                <label for="txtDomain">密码</label>
                                <input type="text" name="pass" class="form-control" placeholder="登录密码" autocomplete="off" required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain">联系人QQ</label>
                                <input type="text" name="qq" class="form-control" placeholder="联系人QQ" autocomplete="off" required/>
                            </div>
                            <div class="form-group">
                                <label for="txtDomain"><i class="fa fa-key"></i>用户KEY<input class="btn btn-primary btn-xs" type= "button" name= "Submit1 " value= "生成" onclick= "show()"></label>
                                <input type="text" name="syskey" id="syskey"  class="form-control" placeholder="可手动输入或者点击生成" value='<?php echo $syskey?>'  required/>
 					<script language=javascript> 
						function show() 
						{ 
						var str= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 
						var result= " " 
						for(var i=0;i <32;i++) 
						{ 
						var temp=Math.floor(Math.random()*36) 
						result+=str.charAt(temp) 
						} 
						hash = result.MD5();
						document.getElementById( "syskey").value=hash
						} 
					</script>
                            </div>
							
                            <div class="form-group">
							  <label>授权时间</label>
							  <select name="time" class="form-control">
								<option value="+1day">天卡 原价：<?php echo $jg1;?>元</option>
								<option value="+7day">周卡 原价：<?php echo $jg2;?>元</option>
								<option value="+1month">月卡 原价：<?php echo $jg3;?>元</option>
								<option value="+3month">季卡 原价：<?php echo $jg4;?>元</option>
								<option value="+1year">年卡 原价：<?php echo $jg5;?>元</option>
								<option value="">永久 原价：<?php echo $jg6;?>元</option>
							  </select>
							</div>
							<span class="help-block" ><font color='red'>您是<?=$dl?>，尊享<?=$zhekou?>*原价</font></span>
			<div class="form-group">
				<label for="txtDomain">备注</label>
				<input type="text" name="bz" class="form-control" placeholder="备注"/>
			</div>
			<div id="bottom" >
			  <button class="btn btn-info" type="submit" value="true" id="submit"/><strong>添加授权</strong></button>
            </div>
                        </form>
                    </section>
                    <!--work progress end-->
                </div>

        </section>
    </section>
    <!--main content end-->

<?php include 'footer.php';?>
